package com.chao.yyks.modular.config.service.impl;

import com.chao.yyks.modular.config.mapper.ResourceMapper;
import com.chao.common.util.StrUtile;
import com.chao.common.util.file.FileUpload;
import com.chao.common.util.file.SysFileService;
import com.chao.common.util.reaction.PageList;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文件上传
 */
@Slf4j
@Service("fileService")
public class SysFileServiceImpl implements SysFileService {

    @Autowired
    private ResourceMapper resourceMapper;

    @Override
    public PageList<FileUpload> selectResourceByRelationId(String objectId, String objectField) {
        return resourceMapper.selectResourceByList(objectId,objectField);
    }

    @Override
    public Integer deleteResourceByRelationId(String objectId, String objectField) {
        return resourceMapper.deleteDataResource(objectId,objectField);
    }

    @Override
    public Integer insertResourceList(List<FileUpload> fileList) {
        return resourceMapper.insertAllResource(fileList);
    }

    @Override
    public Integer insertResource(FileUpload fileUpload) {
        return resourceMapper.insertResource(fileUpload);
    }

    /**
     * 查询多个关联附件
     */
    @Override
    public List<FileUpload> selectResourceByObjectIds(String[] objectIds, String objectField){
        if(StrUtile.isEmpty(objectField)){
            objectField = null;
        }
        return resourceMapper.selectResourceByObjectIds(objectIds, objectField);
    }
}
